﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.Serialization;

namespace LambdaToSql.EntityModel
{
    [Serializable]
    [DataContract]
    internal abstract class InsertEntity<T> : BaseEntity<T> where T : class, new()
    {
        #region Base

        /// <summary>
        /// sql 参数
        /// </summary>
        [DataMember]
        public List<LambdaToSql.EntityModel.DataParameter> Parameters { get; set; }

        /// <summary>
        /// 添加字段
        /// </summary>
        [DataMember]
        public List<string> Fields { get; set; }

        /// <summary>
        /// 忽略字段
        /// </summary>
        [DataMember]
        public List<string> IgnoreFields { get; set; }

        /// <summary>
        /// 添加包含字段
        /// </summary>
        [DataMember]
        public List<string> InsertColumns { get; set; }

        /// <summary>
        /// 添加字段参数 into 后面的
        /// </summary>
        [DataMember]
        public List<string> AddFields { get; set; }

        /// <summary>
        /// 数据对象
        /// </summary>
        [DataMember]
        public T Obj { get; set; }

        #endregion

        #region Sql Template

        /// <summary>
        /// 添加模板
        /// </summary>
        [DataMember]
        public virtual string InsertTemplate
        {
            get
            {
                return "insert into " + this.TableName + " ({0}) values({1})";
            }
        }
        #endregion

        public InsertEntity(LambdaToSql.EntityModel.DbContext context) : base(context)
        {
            this.Parameters = new List<LambdaToSql.EntityModel.DataParameter>();
            this.Fields = new List<string>();
            this.AddFields = new List<string>();
            this.IgnoreFields = new List<string>();
            this.InsertColumns = new List<string>();
        }
    }
}
